package com.xcl.controller;

import com.xcl.pojo.OutsourcingCost;
import com.xcl.service.FinancingServiceInter;
import com.xcl.service.OutsourcingCostServiceInter;
import com.zzg.entity.Outsourcing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName OutsourcingCostController
 * @Description 外包费用的控制器
 * @Author: xiaochaolei
 * @date 2021/7/23 16:30
 * @Version 1. 0
 */
@Controller
public class OutsourcingCostController {
    @Autowired
    OutsourcingCostServiceInter outsourcingCostServiceInter;
    /**
     * 分页查询以及多条件查询
     * @param page 页码数
     * @param limit 条目数
     * @param outsourcingOrder 外包单号
     * @param waybill_id 运单号
     * @param eeforwardingUnit 收货单位
     * @param forwardingUnit 发货单位
     * @param date 转包日期
     * @param type 外包类型
     * @param loname 承包单位
     * @param city 出发地
     * @return map类型的集合
     */
    @GetMapping(value = "/OutsourcingCostControllerGetAllOutsourcingCost", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> getAllOutsourcingCost(int page,int limit,String outsourcingOrder,String  waybill_id,String eeforwardingUnit,String forwardingUnit
    ,String date,String type,String loname,String city){
        Map<String,Object> map=new HashMap<>();
        List<OutsourcingCost> allOutsourcingCostByLimit = outsourcingCostServiceInter.getAllOutsourcingCostByLimit(page, limit,outsourcingOrder,waybill_id,eeforwardingUnit,forwardingUnit,date,type,loname,city
        );
        map.put("code","0");
        map.put("msg","0");
        map.put("count",outsourcingCostServiceInter.getAllOutsourcingCost().size());
        map.put("data",allOutsourcingCostByLimit);
        return map;
    }

    /**
     * 根据外包单号查询到外包订单号
     * @param id 外包单号
     * @return 是否成功
     */
    @PostMapping(value = "/OutsourcingCostControllerUpdateVerification", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String updateVerification(String id){
        //根据外包单号得到外包信息
        Outsourcing outsourcingByOutsourcingorder = outsourcingCostServiceInter.getOutsourcingByOutsourcingorder(id);
        //修改
         if (outsourcingCostServiceInter.updateCostBreakdown(outsourcingByOutsourcingorder)>0){
              return "成功";
          }
        return "失败";
    }

}
